const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: "",
    imagelist: [{
        title: "匠人名录",
        imgurl: "/images/匠人集.png",
        url: "/packageA/pages/jiangrenji/jiangrenji"
      },
      {
        title: "全景展览",
        imgurl: "/images/vr.png",
        url: "/packageA/pages/vr/vr"
      },
      {
        title: "新闻资讯",
        imgurl: "/images/研学.png",
        url: "/packageA/pages/news/news"
      },
      {
        title: "非遗课程",
        imgurl: "/images/课程 (2).png",
        url: "/packageA/pages/course/course"
      },
      {
        title: "精彩活动",
        imgurl: "/images/4.png",
        url:"/packageA/pages/huodong/huodong"
      },
      {
        title: "非遗圈儿",
        imgurl: "/images/2.png",
        url:"/packageA/pages/pyq/pyq"
      },
    ],
    imagelist1: {},
    jiangren: {},
    historyList: [],
    productList: [],
    news:{},
    huodong:{}
  },
  click(e) {
    wx.navigateTo({
      url: '/packageA/pages/detail/detail?id=' + e.currentTarget.dataset.id,
    })
  },



  // 通过数据库获取数据
  getdata() {
    db.collection("jiangrenji")
      .where({
        home:db.RegExp({
          regexp:"true",
          options:"i"//大小写不区分
        })
      })
      .get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          jiangren: res.data
        })
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },
  // 通过数据库获取数据
  getdata1() {
    db.collection("article").limit(3).skip(1)
      .get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          imagelist1: res.data
        })
        console.log(this.data.imagelist1);
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },


  getdata3() {
    db.collection("huodong").limit(3)
      .get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          huodong: res.data
        })
        console.log(this.data.huodong);
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },

  fun2(){
    wx.navigateTo({
      url: '/packageA/pages/jiangrenji/jiangrenji',
    })
  },

  // 通过数据库获取数据
  getdata2() {
    db.collection("article").limit(3).skip(4)
      .get()
      .then(res => {
        console.log("获取数据成功", res);
        this.setData({
          news: res.data
        })
        // console.log(this.data.imagelist1);
      })
      .catch(err => {
        console.log("获取数据失败", err);
      })
  },

  onSearch() {
 
    wx.navigateTo({
      url: '/packageA/pages/search/search?key=' + this.data.value,
    })
    this.setData({
      value:""
    })
  },

  oninput(e) {
    // console.log(e.detail);
    this.setData({
      value: e.detail
    })
    // console.log(this.data.value);
  },

  tiaozhuan(e){
    console.log(e);
    wx.navigateTo({
      url: '/packageA/pages/huodongdetail/huodongdeyail?id='+e.currentTarget.dataset.id , 
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const id=wx.getStorageSync('id') 
    if(id){
    }
    else{
        wx.reLaunch({
        url: '/pages/login/login',
      })
    }
    this.getdata()
    this.getdata1()
    this.getdata2()
    this.getdata3()
  },
  fun1() {
    wx.reLaunch({
      url: '/packageA/pages/news/news',
    })
  },
  fun3(){
    wx.navigateTo({
      url: '/packageA/pages/huodong/huodong',
    })
  },
//点击新闻跳转
navtodetail(e){
  console.log(e.currentTarget.dataset.id);
  wx.navigateTo({
    url: '/packageA/pages/newsdetail/newsdetail?id='+e.currentTarget.dataset.id,
  })
},


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})